package com.zqxx.examine.management.service;

import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zqxx.examine.common.utils.MenuItem;
import com.zqxx.examine.management.persistence.SystemMapper;
@Service
public class SystemService {
	  @Autowired
	  private SystemMapper systemMapper;
	  
	  public LinkedHashMap<String, MenuItem> getMenuItemsByAuthority(String authority)
	  {
	    List<MenuItem> ml = this.systemMapper.getMenuItemsByAuthority(authority);
	    
	    LinkedHashMap<String, MenuItem> map = new LinkedHashMap();
	    for (MenuItem item : ml) {
	      if (item.getParentId().equals("-1"))
	      {
	        LinkedHashMap<String, MenuItem> childs = new LinkedHashMap();
	        for (MenuItem mi : ml) {
	          if (mi.getParentId().equals(item.getMenuId())) {
	            childs.put(mi.getMenuId(), mi);
	          }
	        }
	        item.setChildMap(childs);
	        map.put(item.getMenuId(), item);
	      }
	    }
	    return map;
	  }
}
